package patterns;

import interfaces.Printer;

import java.util.Arrays;

/**
 * Created by pc on 2015/2/6.
 */
public class SimplePrinter implements Printer {
    String [] workQueue;
    int currJobIndex = 0;
    {
       workQueue =  new String[Printer.max_queue_size];
    }
    @Override
    public void queueJob(String docName) {
        workQueue[currJobIndex] = docName;
        currJobIndex++;
    }

    @Override
    public void print() {
        while (currJobIndex > 0){
            //1) loop array
            /*
            for (int i=0; i<currJobIndex; i++){
                System.out.println("printing job " + i + ": " + workQueue[i]);
            }
            currJobIndex = 0;
            */
            
            //2) arraycopy, mimic queue
            System.out.println("before: " + Arrays.toString(workQueue));
            System.out.println(workQueue[0]);
            System.arraycopy(workQueue, 1, workQueue, 0, currJobIndex--);
            System.out.println("after: " + Arrays.toString(workQueue));
        }
    }

    @Override
    public void displayQueue() {
        System.out.println(Arrays.toString(workQueue));
    }
}
